package com.mission.schedule.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;

import com.mission.schedule.R;
import com.mission.schedule.applcation.App;
import com.mission.schedule.bean.RepeatBean;
import com.mission.schedule.clock.RepeatDateUtil;
import com.mission.schedule.constants.Const;
import com.mission.schedule.constants.ShareFile;
import com.mission.schedule.sinaadd.BaseDialog;
import com.mission.schedule.utils.ActivityManager1;
import com.mission.schedule.utils.CalendarChange;
import com.mission.schedule.utils.DateUtil;
import com.mission.schedule.utils.MyLinearLayout;
import com.mission.schedule.utils.SharedPrefUtil;
import com.mission.schedule.utils.StringUtils;
import com.mission.schedule.utils.Utils;
import com.mission.schedule.view.CycleWheelView;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by liwei on 2017/8/18.
 */

public class PhoneCodeLoginNewNextActivity extends Activity implements View.OnClickListener {

    ActivityManager1 activityManager = null;
    Context context;
    SharedPrefUtil sharedPrefUtil;
    boolean login = false;
    Map<Integer, Boolean> map = new HashMap<>();
    List<String> list = new ArrayList<>();
    TextView t1, t2, t3, t4, t5, t6, t7, t8;
    ImageView i1, i2, i3, i4, i5, i6, i7, i8;
    List<ImageView> imageViews = new ArrayList<>();
    String[] contents = {"签到送积分", "睡觉", "周六大转盘", "问候父母", "还花呗", "还信用卡", "我的生日", "我的农历生日"};
    Button login_button;

    private static final int REQUESTCODE_WEEK = 4;// 周
    private static final int REQUESTCODE_DAY = 5;// 每月的天
    private static final int REQUESTCODE_DATE = 6;// 日期(每年)


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login_new_next);
        context = this;
        sharedPrefUtil = new SharedPrefUtil(this, ShareFile.USERFILE);
        activityManager = ActivityManager1.getInstance();
        activityManager.addActivities(this);//ISLOGINNEWNEXT
        sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.ISLOGINNEWNEXT, "1");
        USERID = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.USERID, "");

        t1 = findViewById(R.id.t1);
        t2 = findViewById(R.id.t2);
        t3 = findViewById(R.id.t3);
        t4 = findViewById(R.id.t4);
        t5 = findViewById(R.id.t5);
        t6 = findViewById(R.id.t6);
        t7 = findViewById(R.id.t7);
        t8 = findViewById(R.id.t8);
        i1 = findViewById(R.id.i1);
        i2 = findViewById(R.id.i2);
        i3 = findViewById(R.id.i3);
        i4 = findViewById(R.id.i4);
        i5 = findViewById(R.id.i5);
        i6 = findViewById(R.id.i6);
        i7 = findViewById(R.id.i7);
        i8 = findViewById(R.id.i8);
        login_button = findViewById(R.id.login_button);
        imageViews.add(i1);
        imageViews.add(i2);
        imageViews.add(i3);
        imageViews.add(i4);
        imageViews.add(i5);
        imageViews.add(i6);
        imageViews.add(i7);
        imageViews.add(i8);

        map.put(0, false);
        map.put(1, false);
        map.put(2, false);
        map.put(3, false);
        map.put(4, false);
        map.put(5, false);
        map.put(6, false);
        map.put(7, false);


        t1.setOnClickListener(this);
        t2.setOnClickListener(this);
        t3.setOnClickListener(this);
        t4.setOnClickListener(this);
        t5.setOnClickListener(this);
        t6.setOnClickListener(this);
        t7.setOnClickListener(this);
        t8.setOnClickListener(this);
        t7.setText(Today() + " 全天");

        findViewById(R.id.login_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String maxTitleId;
                RepeatBean bean;
                String time, week, str;
                int displayTime = 0;
                for (String i : list) {
                    switch (Integer.valueOf(i)) {
                        case 0:
                            maxTitleId = DateUtil.nowTime2();
                            time = t1.getText().toString().equals("全天") ? "23:59" : t1.getText().toString();
                            displayTime = t1.getText().toString().equals("全天") ? 0 : 1;
                            bean = RepeatDateUtil.dateTimeToChildAlarmDate(time, 1, "", "",time.equals("23:59") ? "0" : "1");
                            App.getDBcApplication().insertCLRepeatTableData(0, 0,
                                    displayTime, 1, 1, 0, 0, 0, 1,
                                    "[]", bean.repNextCreatedTime,
                                    bean.repLastCreatedTime,
                                    DateUtil.formatDateTime(new Date()),
                                    bean.repNextCreatedTime, contents[0],
                                    DateUtil.formatDateTime(new Date()), maxTitleId, "0",
                                    time, "完成任务", "g_88",
                                    DateUtil.formatDateTime(new Date()), 0, "", 0,
                                    "", "", 0, 0, 0, "", "",
                                    0, 0, "", 0, 0, "0", "","","","","","");
                            App.getDBcApplication().insertScheduleData(contents[0],
                                    bean.repNextCreatedTime.substring(0, 10),
                                    bean.repNextCreatedTime.substring(11, 16),
                                    1, 0, displayTime, 0, 0, 0,
                                    0, bean.repNextCreatedTime, "", 0, maxTitleId, "0",
                                    App.getDBcApplication().repschId, bean.repNextCreatedTime,
                                    DateUtil.formatDateTime(new Date()), 0, 0,
                                    1, "完成任务", "g_88", "", 0, 0,
                                    0, "", "", 0, 0, 0, 0, "", "0", "0");
                            App.getDBcApplication().updateRepeatremark2(App.getDBcApplication().repschId + "", "100");
                            App.getDBcApplication().updateRepeatTimeNextDate(App.getDBcApplication().repschId + "", bean.repNextCreatedTime);
                            break;
                        case 1:
                            maxTitleId = DateUtil.nowTime2();
                            time = t2.getText().toString().equals("全天") ? "23:59" : t2.getText().toString();
                            displayTime = t2.getText().toString().equals("全天") ? 0 : 1;
                            bean = RepeatDateUtil.dateTimeToChildAlarmDate(time, 1, "", "",time.equals("23:59") ? "0" : "1");
                            App.getDBcApplication().insertCLRepeatTableData(0, 0,
                                    displayTime, 1, 1, 0, 0, 0, 1,
                                    "[]", bean.repNextCreatedTime,
                                    bean.repLastCreatedTime,
                                    DateUtil.formatDateTime(new Date()),
                                    bean.repNextCreatedTime, contents[1],
                                    DateUtil.formatDateTime(new Date()), maxTitleId, "0",
                                    time, "完成任务", "g_88",
                                    DateUtil.formatDateTime(new Date()), 0, "", 0,
                                    "", "", 0, 0, 0, "", "",
                                    0, 0, "", 0, 0, "0", "","","","","","");
                            App.getDBcApplication().insertScheduleData(contents[1],
                                    bean.repNextCreatedTime.substring(0, 10),
                                    bean.repNextCreatedTime.substring(11, 16),
                                    1, 0, displayTime, 0, 0, 0,
                                    0, bean.repNextCreatedTime, "", 0, maxTitleId, "0",
                                    App.getDBcApplication().repschId, bean.repNextCreatedTime,
                                    DateUtil.formatDateTime(new Date()), 0, 0,
                                    1, "完成任务", "g_88", "", 0, 0,
                                    0, "", "", 0, 0, 0, 0, "", "0", "0");
                            App.getDBcApplication().updateRepeatTimeNextDate(App.getDBcApplication().repschId + "", bean.repNextCreatedTime);
                            break;
                        case 2:
                            maxTitleId = DateUtil.nowTime2();
                            week = t3.getText().toString().split(" ")[0];
                            bean = RepeatDateUtil.dateTimeToChildAlarmDate("23:59", 2, week.replace("周", "星期"), "","0");
                            if (week.contains("周")) {
                                if ("一".equals(week.substring(2, week.length()))) {
                                    str = "[" + "\"" + 1 + "\"" + "]";
                                } else if ("二".equals(week.substring(2, week.length()))) {
                                    str = "[" + "\"" + 2 + "\"" + "]";
                                } else if ("三".equals(week.substring(2, week.length()))) {
                                    str = "[" + "\"" + 3 + "\"" + "]";
                                } else if ("四".equals(week.substring(2, week.length()))) {
                                    str = "[" + "\"" + 4 + "\"" + "]";
                                } else if ("五".equals(week.substring(2, week.length()))) {
                                    str = "[" + "\"" + 5 + "\"" + "]";
                                } else if ("六".equals(week.substring(2, week.length()))) {
                                    str = "[" + "\"" + 6 + "\"" + "]";
                                } else {
                                    str = "[" + "\"" + 7 + "\"" + "]";
                                }

                            } else {
                                if ("一".equals(week)) {
                                    str = "[" + "\"" + 1 + "\"" + "]";
                                } else if ("二".equals(week)) {
                                    str = "[" + "\"" + 2 + "\"" + "]";
                                } else if ("三".equals(week)) {
                                    str = "[" + "\"" + 3 + "\"" + "]";
                                } else if ("四".equals(week)) {
                                    str = "[" + "\"" + 4 + "\"" + "]";
                                } else if ("五".equals(week)) {
                                    str = "[" + "\"" + 5 + "\"" + "]";
                                } else if ("六".equals(week)) {
                                    str = "[" + "\"" + 6 + "\"" + "]";
                                } else {
                                    str = "[" + "\"" + 7 + "\"" + "]";
                                }
                            }
                            App.getDBcApplication().insertCLRepeatTableData(0, 0,
                                    0, 2, 1, 0, 0, 0, 1,
                                    str, bean.repNextCreatedTime,
                                    bean.repLastCreatedTime,
                                    DateUtil.formatDateTime(new Date()),
                                    bean.repNextCreatedTime, contents[2],
                                    DateUtil.formatDateTime(new Date()), maxTitleId, "0",
                                    "23:59", "完成任务", "g_88",
                                    DateUtil.formatDateTime(new Date()), 0, "", 0,
                                    "", "", 0, 0, 0, "", "",
                                    0, 0, "", 0, 0, "0", "","","","","","");
                            App.getDBcApplication().insertScheduleData(contents[2],
                                    bean.repNextCreatedTime.substring(0, 10),
                                    bean.repNextCreatedTime.substring(11, 16),
                                    1, 0, 0, 0, 0, 0,
                                    0, bean.repNextCreatedTime, "", 0, maxTitleId, "0",
                                    App.getDBcApplication().repschId, bean.repNextCreatedTime,
                                    DateUtil.formatDateTime(new Date()), 0, 0,
                                    1, "完成任务", "g_88", "", 0, 0,
                                    0, "", "", 0, 0, 0, 0, "", "0", "0");
                            App.getDBcApplication().updateRepeatremark2(App.getDBcApplication().repschId + "", "103");
                            App.getDBcApplication().updateRepeatTimeNextDate(App.getDBcApplication().repschId + "", bean.repNextCreatedTime);
                            break;
                        case 3:
                            maxTitleId = DateUtil.nowTime2();
                            week = t4.getText().toString().split(" ")[0];
                            bean = RepeatDateUtil.dateTimeToChildAlarmDate("20:00", 2, week.replace("周", "星期"), "","1");
                            if (week.contains("周")) {
                                if ("一".equals(week.substring(2, week.length()))) {
                                    str = "[" + "\"" + 1 + "\"" + "]";
                                } else if ("二".equals(week.substring(2, week.length()))) {
                                    str = "[" + "\"" + 2 + "\"" + "]";
                                } else if ("三".equals(week.substring(2, week.length()))) {
                                    str = "[" + "\"" + 3 + "\"" + "]";
                                } else if ("四".equals(week.substring(2, week.length()))) {
                                    str = "[" + "\"" + 4 + "\"" + "]";
                                } else if ("五".equals(week.substring(2, week.length()))) {
                                    str = "[" + "\"" + 5 + "\"" + "]";
                                } else if ("六".equals(week.substring(2, week.length()))) {
                                    str = "[" + "\"" + 6 + "\"" + "]";
                                } else {
                                    str = "[" + "\"" + 7 + "\"" + "]";
                                }

                            } else {
                                if ("一".equals(week)) {
                                    str = "[" + "\"" + 1 + "\"" + "]";
                                } else if ("二".equals(week)) {
                                    str = "[" + "\"" + 2 + "\"" + "]";
                                } else if ("三".equals(week)) {
                                    str = "[" + "\"" + 3 + "\"" + "]";
                                } else if ("四".equals(week)) {
                                    str = "[" + "\"" + 4 + "\"" + "]";
                                } else if ("五".equals(week)) {
                                    str = "[" + "\"" + 5 + "\"" + "]";
                                } else if ("六".equals(week)) {
                                    str = "[" + "\"" + 6 + "\"" + "]";
                                } else {
                                    str = "[" + "\"" + 7 + "\"" + "]";
                                }
                            }
                            App.getDBcApplication().insertCLRepeatTableData(0, 0,
                                    1, 2, 1, 0, 0, 0, 1,
                                    str, bean.repNextCreatedTime,
                                    bean.repLastCreatedTime,
                                    DateUtil.formatDateTime(new Date()),
                                    bean.repNextCreatedTime, contents[3],
                                    DateUtil.formatDateTime(new Date()), maxTitleId, "0",
                                    "20:00", "完成任务", "g_88",
                                    DateUtil.formatDateTime(new Date()), 0, "", 0,
                                    "", "", 0, 0, 0, "", "",
                                    0, 0, "", 0, 0, "0", "","","","","","");
                            App.getDBcApplication().insertScheduleData(contents[3],
                                    bean.repNextCreatedTime.substring(0, 10),
                                    bean.repNextCreatedTime.substring(11, 16),
                                    1, 0, 1, 0, 0, 0,
                                    0, bean.repNextCreatedTime, "", 0, maxTitleId, "0",
                                    App.getDBcApplication().repschId, bean.repNextCreatedTime,
                                    DateUtil.formatDateTime(new Date()), 0, 0,
                                    1, "完成任务", "g_88", "", 0, 0,
                                    0, "", "", 0, 0, 0, 0, "", "0", "0");
                            App.getDBcApplication().updateRepeatTimeNextDate(App.getDBcApplication().repschId + "", bean.repNextCreatedTime);

                            break;
                        case 4:
                            maxTitleId = DateUtil.nowTime2();
                            String day1 = t5.getText().toString().split(" ")[0];
                            bean = RepeatDateUtil.dateTimeToChildAlarmDate("23:59", 3, day1, "", "0");
                            if (day1.contains("日")) {
                                str = "[" + "\"" + day1.substring(0, day1.length() - 1) + "\"" + "]";
                            } else {
                                str = "[" + "\"" + day1 + "\"" + "]";
                            }
                            App.getDBcApplication().insertCLRepeatTableData(0, 0,
                                    0, 3, 1, 0, 0, 0, 1,
                                    str, bean.repNextCreatedTime,
                                    bean.repLastCreatedTime,
                                    DateUtil.formatDateTime(new Date()),
                                    bean.repNextCreatedTime, contents[4],
                                    DateUtil.formatDateTime(new Date()), maxTitleId, "0",
                                    "23:59", "完成任务", "g_88",
                                    DateUtil.formatDateTime(new Date()), 0, "", 0,
                                    "", "", 0, 0, 0, "", "",
                                    0, 0, "", 0, 0, "0", "","","","","","");
                            App.getDBcApplication().insertScheduleData(contents[4],
                                    bean.repNextCreatedTime.substring(0, 10),
                                    bean.repNextCreatedTime.substring(11, 16),
                                    1, 0, 0, 0, 0, 0,
                                    0, bean.repNextCreatedTime, "", 0, maxTitleId, "0",
                                    App.getDBcApplication().repschId, bean.repNextCreatedTime,
                                    DateUtil.formatDateTime(new Date()), 0, 0,
                                    1, "完成任务", "g_88", "", 0, 0,
                                    0, "", "", 0, 0, 0, 0, "", "0", "0");
                            App.getDBcApplication().updateRepeatTimeNextDate(App.getDBcApplication().repschId + "", bean.repNextCreatedTime);

                            break;
                        case 5:
                            maxTitleId = DateUtil.nowTime2();
                            String day2 = t6.getText().toString().split(" ")[0];
                            bean = RepeatDateUtil.dateTimeToChildAlarmDate("23:59", 3, day2, "","0");
                            if (day2.contains("日")) {
                                str = "[" + "\"" + day2.substring(0, day2.length() - 1) + "\"" + "]";
                            } else {
                                str = "[" + "\"" + day2 + "\"" + "]";
                            }
                            App.getDBcApplication().insertCLRepeatTableData(0, 0,
                                    0, 3, 1, 0, 0, 0, 1,
                                    str, bean.repNextCreatedTime,
                                    bean.repLastCreatedTime,
                                    DateUtil.formatDateTime(new Date()),
                                    bean.repNextCreatedTime, contents[5],
                                    DateUtil.formatDateTime(new Date()), maxTitleId, "0",
                                    "23:59", "完成任务", "g_88",
                                    DateUtil.formatDateTime(new Date()), 0, "", 0,
                                    "", "", 0, 0, 0, "", "",
                                    0, 0, "", 0, 0, "0", "","","","","","");
                            App.getDBcApplication().insertScheduleData(contents[5],
                                    bean.repNextCreatedTime.substring(0, 10),
                                    bean.repNextCreatedTime.substring(11, 16),
                                    1, 0, 0, 0, 0, 0,
                                    0, bean.repNextCreatedTime, "", 0, maxTitleId, "0",
                                    App.getDBcApplication().repschId, bean.repNextCreatedTime,
                                    DateUtil.formatDateTime(new Date()), 0, 0,
                                    1, "完成任务", "g_88", "", 0, 0,
                                    0, "", "", 0, 0, 0, 0, "", "0", "0");
                            App.getDBcApplication().updateRepeatTimeNextDate(App.getDBcApplication().repschId + "", bean.repNextCreatedTime);

                            break;
                        case 6:
                            maxTitleId = DateUtil.nowTime2();
                            String day3 = t7.getText().toString().split(" ")[0];
                            String ty1 = day3.substring(2, 3).equals("-") ? "0" : "1";
                            str = "[" + "\"" + day3 + "\"" + "]";
                            bean = RepeatDateUtil.dateTimeToChildAlarmDate("23:59", 4, day3, ty1,"0");
                            App.getDBcApplication().insertCLRepeatTableData(0, 0,
                                    0, 4, 1, 0, 0, 0, 1,
                                    str, bean.repNextCreatedTime,
                                    bean.repLastCreatedTime,
                                    DateUtil.formatDateTime(new Date()),
                                    bean.repNextCreatedTime, contents[6],
                                    DateUtil.formatDateTime(new Date()), maxTitleId, "0",
                                    "23:59", "完成任务", "g_88",
                                    DateUtil.formatDateTime(new Date()), 0, "", 0,
                                    "", "", 0, 0, 0, "", "",
                                    0, 0, "", 0, 0, "0", "","","","","","");
                            App.getDBcApplication().insertScheduleData(contents[6],
                                    bean.repNextCreatedTime.substring(0, 10),
                                    bean.repNextCreatedTime.substring(11, 16),
                                    1, 0, 0, 0, 0, 0,
                                    0, bean.repNextCreatedTime, "", 0, maxTitleId, "0",
                                    App.getDBcApplication().repschId, bean.repNextCreatedTime,
                                    DateUtil.formatDateTime(new Date()), 0, 0,
                                    1, "完成任务", "g_88", "", 0, 0,
                                    0, "", "", 0, 0, 0, 0, "", "0", "0");
                            App.getDBcApplication().updateRepeatTimeNextDate(App.getDBcApplication().repschId + "", bean.repNextCreatedTime);

                            break;
                        case 7:
                            maxTitleId = DateUtil.nowTime2();
                            String day4 = t8.getText().toString().split(" ")[0];
                            String ty = day4.substring(2, 3).equals("-") ? "0" : "1";
                            str = "[" + "\"" + day4 + "\"" + "]";
                            bean = RepeatDateUtil.dateTimeToChildAlarmDate("23:59", 6, day4, ty,"0");
                            App.getDBcApplication().insertCLRepeatTableData(0, 0,
                                    0, 6, 1, 0, 0, 0, 1,
                                    str, bean.repNextCreatedTime,
                                    bean.repLastCreatedTime,
                                    DateUtil.formatDateTime(new Date()),
                                    bean.repNextCreatedTime, contents[7],
                                    DateUtil.formatDateTime(new Date()), maxTitleId, "0",
                                    "23:59", "完成任务", "g_88",
                                    DateUtil.formatDateTime(new Date()), 0, "", 0,
                                    "", "", 0, 0, 0, "", "",
                                    0, 0, "", 0, 0, "0", "","","","","","");
                            App.getDBcApplication().insertScheduleData(contents[7],
                                    bean.repNextCreatedTime.substring(0, 10),
                                    bean.repNextCreatedTime.substring(11, 16),
                                    1, 0, 0, 0, 0, 0,
                                    0, bean.repNextCreatedTime, "", 0, maxTitleId, "0",
                                    App.getDBcApplication().repschId, bean.repNextCreatedTime,
                                    DateUtil.formatDateTime(new Date()), 0, 0,
                                    1, "完成任务", "g_88", "", 0, 0,
                                    0, "", "", 0, 0, 0, 0, "", "0", "0");
                            App.getDBcApplication().updateRepeatTimeNextDate(App.getDBcApplication().repschId + "", bean.repNextCreatedTime);
                            break;
                    }
                }
                activityManager.doAllActivityFinish();
                Intent intent = new Intent(Const.SHUAXINDATA);
                intent.putExtra("data", "success");
                intent.putExtra("index", 1);
                intent.putExtra("what", 2);
                sendBroadcast(intent);
                sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.ISLOGINNEWNEXT, "0");
                startActivity(new Intent(context, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
            }
        });

        findViewById(R.id.l1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                checkimage(0);
            }
        });
        findViewById(R.id.l2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                checkimage(1);
            }
        });
        findViewById(R.id.l3).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                checkimage(2);
            }
        });
        findViewById(R.id.l4).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                checkimage(3);
            }
        });
        findViewById(R.id.l5).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                checkimage(4);
            }
        });
        findViewById(R.id.l6).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                checkimage(5);
            }
        });
        findViewById(R.id.l7).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                checkimage(6);
            }
        });
        findViewById(R.id.l8).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                checkimage(7);
            }
        });
    }

    String USERID = "";

    private void checkimage(int index) {
        if (map.get(index)) {
            map.put(index, false);
            list.remove(index + "");
            imageViews.get(index).setBackground(getResources().getDrawable(R.mipmap.icon_quan));
        } else {
            list.add(index + "");
            map.put(index, true);
            imageViews.get(index).setBackground(getResources().getDrawable(R.mipmap.icon_santail4));
        }

        if (list.size() >= 3) {
            login_button.setBackground(getResources().getDrawable(R.drawable.bg_sch_normal_white));
            login_button.setTextColor(Color.BLACK);
            login_button.setEnabled(true);
        } else {
            login_button.setBackground(getResources().getDrawable(R.drawable.login_button));
            login_button.setEnabled(false);
            login_button.setTextColor(Color.WHITE);
        }
    }


    @Override
    public void onBackPressed() {
        return;
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK
                && getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {// 竖屏
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void onClick(View v) {
        Intent intent;
        switch (v.getId()) {
            case R.id.t1:
                if (sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.CLOCKORDER, "0").equals("0")) {
                    dialogMorningTimeOnClick(t1);
                } else {
                    initDiaLog(t1);
                }
                break;
            case R.id.t2:
                if (sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.CLOCKORDER, "0").equals("0")) {
                    dialogMorningTimeOnClick(t2);
                } else {
                    initDiaLog(t2);
                }
                break;
            case R.id.t3:
                Type = 3;
                intent = new Intent(this, WeekActivity.class);
                intent.putExtra("type", 1);
                intent.putExtra("weeks", Week1(t1.getText().toString().trim().split(" ")[0]));
                startActivityForResult(intent, REQUESTCODE_WEEK);
                break;
            case R.id.t4:
                Type = 4;
                intent = new Intent(this, WeekActivity.class);
                intent.putExtra("type", 1);
                intent.putExtra("weeks", Week1(t2.getText().toString().trim().split(" ")[0]));
                startActivityForResult(intent, REQUESTCODE_WEEK);
                break;
            case R.id.t5:
                Type = 5;
                intent = new Intent(this, DayActivity.class);
                intent.putExtra("dayS", DateUtil.nowDay1());
                intent.putExtra("type", 1);
                startActivityForResult(intent, REQUESTCODE_DAY);
                break;
            case R.id.t6:
                Type = 6;
                intent = new Intent(this, DayActivity.class);
                intent.putExtra("dayS", DateUtil.nowDay1());
                intent.putExtra("type", 1);
                startActivityForResult(intent, REQUESTCODE_DAY);
                break;
            case R.id.t7:
                Type = 7;
                intent = new Intent(this, DateSetActivity.class);
                intent.putExtra("month", DateUtil.nowMonth());
                intent.putExtra("day", DateUtil.nowDay1());
                startActivityForResult(intent, REQUESTCODE_DATE);
                break;
            case R.id.t8:
                Type = 8;
                intent = new Intent(this, DateSetActivity.class);
                intent.putExtra("month", DateUtil.nowMonth());
                intent.putExtra("day", DateUtil.nowDay1());
                startActivityForResult(intent, REQUESTCODE_DATE);
                break;
        }
    }

    int Type = 3;

    public static String Today() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd");
        Date date = new Date(System.currentTimeMillis());
        return simpleDateFormat.format(date);
    }

    String weeks, day;
    private String yearType = "0";// 0 公立 1 农历

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (1 == requestCode) {
            if (resultCode == Activity.RESULT_OK) {
                switch (Type) {
                    case 3:
                        t3.setText("周六 全天");
                        break;
                    case 4:
                        t4.setText("周六 20:00");
                        break;
                    case 5:
                        t5.setText("10日 全天");
                        break;
                    case 6:
                        t6.setText("10日 全天");
                        break;
                    case 7:
                        t7.setText(Today() + " 全天");
                    case 8:
                        t8.setText("六月初六 全天");
                        break;
                }
            }
        }

        if (requestCode == REQUESTCODE_WEEK) {// 每周
            if (resultCode == Activity.RESULT_OK) {
                weeks = data.getStringExtra("weeks");
                String w = "";
                for (int i = 0; i < weeks.split(",").length; i++) {
                    if (weeks.split(",")[i].equals("1")) {
                        if (w.equals("")) {
                            w = "周一";
                        } else {
                            w += ",一";
                        }
                    } else if (weeks.split(",")[i].equals("2")) {
                        if (w.equals("")) {
                            w = "周二";
                        } else {
                            w += ",二";
                        }
                    } else if (weeks.split(",")[i].equals("3")) {
                        if (w.equals("")) {
                            w = "周三";
                        } else {
                            w += ",三";
                        }
                    } else if (weeks.split(",")[i].equals("4")) {
                        if (w.equals("")) {
                            w = "周四";
                        } else {
                            w += ",四";
                        }
                    } else if (weeks.split(",")[i].equals("5")) {
                        if (w.equals("")) {
                            w = "周五";
                        } else {
                            w += ",五";
                        }
                    } else if (weeks.split(",")[i].equals("6")) {
                        if (w.equals("")) {
                            w = "周六";
                        } else {
                            w += ",六";
                        }
                    } else if (weeks.split(",")[i].equals("7")) {
                        if (w.equals("")) {
                            w = "周日";
                        } else {
                            w += ",日";
                        }
                    }
                }
                if (Type == 3) {
                    t3.setText(w + " 全天");
                } else if (Type == 4) {
                    t4.setText(w + " 20:00");
                }
            }
        }

        if (requestCode == REQUESTCODE_DAY) {
            if (resultCode == Activity.RESULT_OK) {
                String strDay = data.getStringExtra("dayS");
                if (!"".equals(strDay)) {
                    if (strDay.contains(",")) {
                        String[] days = strDay.split(",");
                        StringBuffer sb = new StringBuffer();
                        for (int i = 0; i < days.length; i++) {
                            day = Integer.parseInt(days[i]) < 10 ? "0"
                                    + Integer.parseInt(days[i]) : Integer.parseInt(days[i])
                                    + "";
                            if (i == days.length - 1) {
                                sb.append(day);
                            } else {
                                sb.append(day + ",");
                            }
                        }
                        if (Type == 5) {
                            t5.setText(sb.toString() + " 全天");
                        } else if (Type == 6) {
                            t6.setText(sb.toString() + " 全天");
                        }

                    } else {
                        day = Integer.parseInt(strDay) < 10 ? "0"
                                + Integer.parseInt(strDay) : Integer.parseInt(strDay)
                                + "";
                        if (Type == 5) {
                            t5.setText(day + "日 全天");
                        } else if (Type == 6) {
                            t6.setText(day + "日 全天");
                        }
                    }

                }
            }
        } else if (requestCode == REQUESTCODE_DATE) {// 每年
            if (resultCode == Activity.RESULT_OK) {
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(new Date());
                String str = "";
                String[] monthStr = getResources().getStringArray(
                        R.array.monthStr);
                String[] lunarStr = getResources().getStringArray(
                        R.array.lunarstr);
                List<String> dateList = data.getStringArrayListExtra("list");
                yearType = data.getStringExtra("type");
                String monthLunar = "";
                String dayLunar = "";
                List<String> mList = new ArrayList<String>();
                if (dateList != null && dateList.size() > 0) {
                    if ("0".equals(yearType)) {
                        for (int i = 0; i < dateList.size(); i++) {
                            if (dateList.size() == 1) {
                                str = dateList.get(i);
                            } else if (dateList.size() == 2) {
                                str = dateList.get(0) + "、" + dateList.get(i);
                            } else if (dateList.size() == 3) {
                                str = dateList.get(0) + "、" + dateList.get(1)
                                        + "、" + dateList.get(i);
                            } else if (dateList.size() == 4) {
                                str = dateList.get(0) + "、" + dateList.get(1)
                                        + "、" + dateList.get(2) + "、"
                                        + dateList.get(i);
                            } else if (dateList.size() == 5) {
                                str = dateList.get(0) + "、" + dateList.get(1)
                                        + "、" + dateList.get(2) + "、"
                                        + dateList.get(3) + "、"
                                        + dateList.get(i);
                            }
                        }
                    } else {
                        for (int i = 0; i < dateList.size(); i++) {
                            for (int j = 1; j <= monthStr.length; j++) {
                                if (Integer
                                        .parseInt(dateList.get(i).split("-")[0]) == j) {
                                    monthLunar = monthStr[j - 1];
                                }
                            }
                            for (int j = 1; j <= lunarStr.length; j++) {
                                if (Integer
                                        .parseInt(dateList.get(i).split("-")[1]) == j) {
                                    dayLunar = lunarStr[j - 1];
                                }
                            }
                            mList.add(monthLunar + dayLunar);
                        }
                        for (int i = 0; i < mList.size(); i++) {
                            if (mList.size() == 1) {
                                str = mList.get(i);
                            } else if (mList.size() == 2) {
                                str = mList.get(0) + "、" + mList.get(i);
                            } else if (mList.size() == 3) {
                                str = mList.get(0) + "、" + mList.get(1) + "、"
                                        + mList.get(i);
                            } else if (mList.size() == 4) {
                                str = mList.get(0) + "、" + mList.get(1) + "、"
                                        + mList.get(2) + "、" + mList.get(i);
                            } else if (mList.size() == 5) {
                                str = mList.get(0) + "、" + mList.get(1) + "、"
                                        + mList.get(2) + "、" + mList.get(3)
                                        + "、" + dateList.get(i);
                            }
                        }
                    }

                    if ("0".equals(yearType)) {
                        if (Type == 7) {
                            t7.setText(str + " 全天");
                        } else if (Type == 8) {
                            t8.setText(str + " 全天");
                        }
                    } else {
                        if (Type == 7) {
                            t7.setText(str + " 全天");
                        } else if (Type == 8) {
                            t8.setText(str + " 全天");
                        }
                    }
                }
            }
        }
    }

    public static String Week(String date) {
        String week = "1";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date today;
        try {
            today = simpleDateFormat.parse(date);
            Calendar c = Calendar.getInstance();
            c.setTime(today);
            int weekday = c.get(Calendar.DAY_OF_WEEK);
            switch (weekday) {
                case 1:
                    week = "7";
                    break;
                case 2:
                    week = "1";
                    break;
                case 3:
                    week = "2";
                    break;
                case 4:
                    week = "3";
                    break;
                case 5:
                    week = "4";
                    break;
                case 6:
                    week = "5";
                    break;
                case 7:
                    week = "6";
                    break;
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return week;//format(today) + " " +
    }

    public static String Week1(String date) {
        String week = "0";
        switch (date) {
            case "周日":
                week = "7";
                break;
            case "周一":
                week = "1";
                break;
            case "周二":
                week = "2";
                break;
            case "周三":
                week = "3";
                break;
            case "周四":
                week = "4";
                break;
            case "周五":
                week = "5";
                break;
            case "周六":
                week = "6";
                break;
        }
        return week;//format(today) + " " +
    }

    private void initDiaLog(TextView time_tv) {
        final BaseDialog dialog = new BaseDialog(context, R.style.dialog_translucent);
        Window window = dialog.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
//        params.alpha = 0.92f;
        window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
        window.setAttributes(params);// 设置生效

        LayoutInflater fac = LayoutInflater.from(context);
        View more_pop_menu = fac.inflate(R.layout.dialog_calender_time, null);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setContentView(more_pop_menu);
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.width = getWindowManager().getDefaultDisplay().getWidth();
        dialog.show();
        dialog.setCallBack(new BaseDialog.CallBack() {
            @Override
            public void onTouchOutside() {
                sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.CLOCKORDER, "1");
                dialog.dismiss();
            }
        });

        new MyClick(dialog, more_pop_menu, time_tv);
    }

    private Animation animationTranslate;
    private RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(0, 0);

    // 移动的动画效果
    /*
     * TranslateAnimation(float fromXDelta, float toXDelta, float
     * fromYDelta,float toYDelta)
     *
     * float fromXDelta:这个参数表示动画开始的点离当前View X坐标上的差值；
     *
     * float toXDelta, 这个参数表示动画结束的点离当前View X坐标上的差值；
     *
     * float fromYDelta, 这个参数表示动画开始的点离当前View Y坐标上的差值；
     *
     * float toYDelta)这个参数表示动画开始的点离当前View Y坐标上的差值；
     */
    protected Animation animTranslate(float toX, float toY, final int x1,
                                      final int y1, final TextView textView, long durationMillis) {
        animationTranslate = new TranslateAnimation(toX, toX, toY, toY);
        animationTranslate.setAnimationListener(new Animation.AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                params = new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.WRAP_CONTENT,
                        RelativeLayout.LayoutParams.WRAP_CONTENT);
                params.setMargins(x1, y1, 0, 0);
                textView.setLayoutParams(params);
                textView.setPadding(12, 7, 12, 7);
                textView.clearAnimation();
            }
        });
        animationTranslate.setDuration(durationMillis);
        return animationTranslate;
    }

    class MyClick implements View.OnClickListener {

        private Dialog dialog;
        private RelativeLayout rela_hour;
        private RelativeLayout rela_minutes;
        private int hours = 12;
        private int minutes = 0;
        private int width;
        private int centerX;
        private int centerY;
        private Calendar calendar;
        private int lastMinutes;
        private TextView dialog_tv_state, dialog_tv_state1;
        private int grState;// 结果为0是上午 结果为1是下午
        private String chooseHour;
        private String chooseMinute;

        private TextView tv_clock_state;
        private LinearLayout ll_clock, state_ll;
        private TextView tv_clock_time;
        private TextView tv_clock_beforetime;
        private TextView time_tv, tv_gt;

        private RelativeLayout date_re;
        String time;

        private MyClick(Dialog dialog, View more_pop_menu, TextView time_tvs) {
            this.dialog = dialog;
            this.time_tv = time_tvs;
            time = time_tvs.getText().toString();
            calendar = Calendar.getInstance();
            // if (isNeedPush) {
            String[] times;

            if ("全天".equals(time)) {
                times = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.ALLTIME, "08:58").split(":");
            } else {
                times = time.split(":");
            }
            calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(times[0]));
            calendar.set(Calendar.MINUTE, Integer.parseInt(times[1]));
            // }
            rela_hour = (RelativeLayout) more_pop_menu
                    .findViewById(R.id.rela_hour);
            rela_minutes = (RelativeLayout) more_pop_menu
                    .findViewById(R.id.rela_minutes);

            dialog_tv_state = (TextView) more_pop_menu
                    .findViewById(R.id.dialog_tv_state);
            date_re = (RelativeLayout) more_pop_menu
                    .findViewById(R.id.date_re);
            dialog_tv_state1 = (TextView) more_pop_menu
                    .findViewById(R.id.dialog_tv_state1);
            state_ll = (LinearLayout) more_pop_menu
                    .findViewById(R.id.state_ll);
            state_ll.setOnClickListener(this);
            tv_clock_state = (TextView) more_pop_menu
                    .findViewById(R.id.tv_clock_state);
            tv_clock_state.setOnClickListener(this);

            tv_gt = (TextView) more_pop_menu.findViewById(R.id.tv_gt);
            tv_gt.setOnClickListener(this);
            ll_clock = (LinearLayout) more_pop_menu.findViewById(R.id.ll_clock);
            ll_clock.setOnClickListener(this);

            tv_clock_time = (TextView) more_pop_menu.findViewById(R.id.tv_clock_time);
            tv_clock_beforetime = (TextView) more_pop_menu.findViewById(R.id.tv_clock_beforetime);

            width = getWindowManager().getDefaultDisplay().getWidth();
            int haf = Utils.dipTopx(context, 20);
            centerX = width / 2 - Utils.dipTopx(context, 16);
            centerY = width / 2 - Utils.dipTopx(context, 16) - haf;

            initclockValue();
            initHour();
            initMinutes();

            grState = calendar.get(Calendar.AM_PM);
//            if (grState == 0) {// 结果为0是上午 结果为1是下午
//                dialog_tv_state.setText("上午");
//            } else {
//                dialog_tv_state.setText("下午");
//            }
            if (grState == 1) {// 上午
                dialog_tv_state1.setTextColor(Color.parseColor("#08f0ff"));
                dialog_tv_state1.setTextSize(30);
                dialog_tv_state.setTextColor(Color.parseColor("#aaaaaa"));
                dialog_tv_state.setTextSize(14);
                grState = 1;
                calendar.set(Calendar.AM_PM, grState);
            } else if (grState == 0) {// 下午
                dialog_tv_state.setTextColor(Color.parseColor("#08f0ff"));
                dialog_tv_state.setTextSize(30);
                dialog_tv_state1.setTextColor(Color.parseColor("#aaaaaa"));
                dialog_tv_state1.setTextSize(14);
                grState = 0;
                calendar.set(Calendar.AM_PM, grState);
            }
        }

        private void initclockValue() {
            tv_clock_time.setText(time);
            if (time.split(":")[0].substring(0, 1).equals("0")) {
                if (Integer.valueOf(time.split(":")[0].substring(1, time.split(":")[0].length())) >= 0 &&
                        Integer.valueOf(time.split(":")[0].substring(1, time.split(":")[0].length())) <= 6) {
                    tv_clock_time.setText("凌晨 " + time);
                }
            }
        }

        private void initHour() {
            int hour = calendar.get(Calendar.HOUR);
            if (hour == 0) {
                hour = 12;
            }
            int hourRadius = Utils.dipTopx(context, 90); // 设置圆半径
            for (int i = 12; i >= 1; i--) {
                int dy = (int) (hourRadius * Math.cos((Math.PI / 6.0) * i));
                int dx = (int) (hourRadius * Math.sin((Math.PI / 6.0) * i));

                int x1 = centerX + dx;
                int y1 = centerY - dy;

                String text = hours < 10 ? "0" + hours : "" + hours;

                TextView textView = new TextView(context);
                textView.setText(text);
                textView.setTextColor(Color.WHITE);
                textView.setTextSize(18.0f);
                textView.setGravity(Gravity.CENTER);
                textView.setLayoutParams(new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.WRAP_CONTENT,
                        LinearLayout.LayoutParams.WRAP_CONTENT));
                textView.setTag(i);
                textView.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        chooseHour = v.getTag().toString();
                        chageHour(Integer.parseInt(chooseHour));
                        calendar.set(Calendar.HOUR,
                                Integer.parseInt(chooseHour));
                        calendar.set(Calendar.MINUTE,
                                Integer.parseInt(chooseMinute));
                        if (grState == 0) {// 上午
                            calendar.set(Calendar.AM_PM, 0);
                        } else if (grState == 1) {// 下午
                            calendar.set(Calendar.AM_PM, 1);
                        }
                        String calendarHour = calendar
                                .get(Calendar.HOUR_OF_DAY) < 10 ? "0"
                                + calendar.get(Calendar.HOUR_OF_DAY) : ""
                                + calendar.get(Calendar.HOUR_OF_DAY);
                        String calendarMinute = calendar.get(Calendar.MINUTE) < 10 ? "0"
                                + calendar.get(Calendar.MINUTE)
                                : "" + calendar.get(Calendar.MINUTE);
                        time_tv.setText(calendarHour + ":" + calendarMinute);
                        tv_clock_time.setText(((0 <= calendar
                                .get(Calendar.HOUR_OF_DAY) && calendar
                                .get(Calendar.HOUR_OF_DAY) <= 6) ? "凌晨" : "") + calendarHour + ":" + calendarMinute);
                    }
                });

                if (hour == i) {
                    if (time.equals("全天")) {
                        textView.setBackgroundDrawable(null);
                    } else {
                        chooseHour = text;
                        textView.setTextColor(Color.WHITE);
                        textView.setBackgroundResource(R.mipmap.icon_shuzi1);
                    }
                } else {
                    textView.setBackgroundDrawable(null);
                }

                rela_hour.addView(textView);

                textView.setAnimation(animTranslate(centerX, centerY, x1, y1, textView, 200));

                hours--;
            }
        }

        private void initMinutes() {
            int minute = calendar.get(Calendar.MINUTE);
            int result = minute % 5;
            if (result != 0) {
                int division = minute / 5;
                minute = division * 5;
            }
            int minutesRadius = Utils.dipTopx(context, 140); // 设置圆半径
            for (int i = 0; i < 12; i++) {
                int dy = (int) (minutesRadius * Math.cos((Math.PI / 6.0) * i));
                int dx = (int) (minutesRadius * Math.sin((Math.PI / 6.0) * i));

                int x1 = centerX + dx;
                int y1 = centerY - dy;

                String text = minutes * 5 < 10 ? "0" + minutes * 5 : "" + minutes * 5;

                TextView textView = new TextView(context);
                textView.setText(text);
                textView.setTextColor(Color.WHITE);
                textView.setTextSize(18.0f);
                textView.setGravity(Gravity.CENTER);
                textView.setLayoutParams(new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.WRAP_CONTENT,
                        LinearLayout.LayoutParams.WRAP_CONTENT));
                textView.setTag(text);
                textView.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        chooseMinute = v.getTag().toString();
                        chageMinutes(Integer.parseInt(chooseMinute) / 5);
                        lastMinutes = Integer.parseInt(chooseMinute) / 5;
                        calendar.set(Calendar.HOUR,
                                Integer.parseInt(chooseHour));
                        calendar.set(Calendar.MINUTE,
                                Integer.parseInt(chooseMinute));
                        if (grState == 0) {// 上午
                            calendar.set(Calendar.AM_PM, 0);
                        } else if (grState == 1) {// 下午
                            calendar.set(Calendar.AM_PM, 1);
                        }
                        String calendarHour = calendar
                                .get(Calendar.HOUR_OF_DAY) < 10 ? "0"
                                + calendar.get(Calendar.HOUR_OF_DAY) : ""
                                + calendar.get(Calendar.HOUR_OF_DAY);
                        String calendarMinute = calendar.get(Calendar.MINUTE) < 10 ? "0"
                                + calendar.get(Calendar.MINUTE)
                                : "" + calendar.get(Calendar.MINUTE);
                        time_tv.setText(calendarHour + ":" + calendarMinute);
                        tv_clock_time.setText(((0 <= calendar
                                .get(Calendar.HOUR_OF_DAY) && calendar
                                .get(Calendar.HOUR_OF_DAY) <= 6) ? "凌晨" : "") + calendarHour + ":" + calendarMinute);
                    }
                });
                if (minute == Integer.parseInt(text)) {
                    if (time.equals("全天")) {
                        textView.setBackgroundDrawable(null);
                    } else {
                        lastMinutes = i;
                        chooseMinute = text;
                        textView.setTextColor(Color.WHITE);
                        textView.setBackgroundResource(R.mipmap.icon_shuzi2);
                    }
                } else {
                    textView.setBackgroundDrawable(null);
                }
                rela_minutes.addView(textView);
                textView.setAnimation(animTranslate(centerX, centerY, x1, y1, textView, 200));

                minutes++;
            }
        }

        private void chageHour(int hours) {
            for (int i = rela_hour.getChildCount() - 1; i >= 0; i--) {
                TextView tv_hour = (TextView) rela_hour.getChildAt(i);
                if (hours == Integer.parseInt(tv_hour.getTag().toString())) {
                    tv_hour.setBackgroundResource(R.mipmap.icon_shuzi1);
                } else {
                    tv_hour.setBackgroundDrawable(null);
                }
            }
        }

        private void chageMinutes(int minutes) {
            TextView textView = (TextView) rela_minutes.getChildAt(lastMinutes);
            textView.setBackgroundDrawable(null);
            TextView tv_minutes = (TextView) rela_minutes.getChildAt(minutes);
            tv_minutes.setBackgroundResource(R.mipmap.icon_shuzi2);
        }


        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.tv_gt:
                    dialogMorningTimeOnClick(time_tv);
                    dialog.dismiss();
                    break;
                case R.id.state_ll:
                    calendar.set(Calendar.HOUR, Integer.parseInt(chooseHour));
                    calendar.set(Calendar.MINUTE, Integer.parseInt(chooseMinute));
                    if (grState == 0) {// 上午
                        dialog_tv_state1.setTextColor(Color.parseColor("#08f0ff"));
                        dialog_tv_state1.setTextSize(30);
                        dialog_tv_state.setTextColor(Color.parseColor("#aaaaaa"));
                        dialog_tv_state.setTextSize(14);
                        grState = 1;
                        calendar.set(Calendar.AM_PM, grState);
                    } else if (grState == 1) {// 下午
                        dialog_tv_state.setTextColor(Color.parseColor("#08f0ff"));
                        dialog_tv_state.setTextSize(30);
                        dialog_tv_state1.setTextColor(Color.parseColor("#aaaaaa"));
                        dialog_tv_state1.setTextSize(14);
                        grState = 0;
                        calendar.set(Calendar.AM_PM, grState);
                    }
//                    dialog_tv_state.startAnimation(AnimationUtils.loadAnimation(context, R.anim.scale_in));
                    String calendarHour = calendar.get(Calendar.HOUR_OF_DAY) < 10 ? "0"
                            + calendar.get(Calendar.HOUR_OF_DAY)
                            : "" + calendar.get(Calendar.HOUR_OF_DAY);
                    String calendarMinute = calendar.get(Calendar.MINUTE) < 10 ? "0"
                            + calendar.get(Calendar.MINUTE)
                            : "" + calendar.get(Calendar.MINUTE);
                    tv_clock_time.setText(((0 <= calendar.get(Calendar.HOUR_OF_DAY) && calendar
                            .get(Calendar.HOUR_OF_DAY) <= 6) ? "凌晨" : "") + calendarHour + ":" + calendarMinute);
                    time_tv.setText(calendarHour + ":" + calendarMinute);
//                    dialog.dismiss();
                    break;

                case R.id.tv_clock_state:
                    // isNeedPush = false;
                    time_tv.setText("全天");
                    // tv_beforetime.setText("");
//                    dialog.dismiss();
                    break;

                case R.id.ll_clock:
//                    if (date_re.getVisibility() == View.VISIBLE){
//                        date_re.setVisibility(View.GONE);
//                        time_ll.setVisibility(View.VISIBLE);
//                    }else {
//                        date_re.setVisibility(View.VISIBLE);
//                        time_ll.setVisibility(View.GONE);
//                    }
                    break;

                default:
                    dialog.dismiss();

                    break;
            }
        }

    }

    private void dialogMorningTimeOnClick(TextView time_tv) {
        final BaseDialog dialog = new BaseDialog(context, R.style.dialog_translucent);
        Window window = dialog.getWindow();
        android.view.WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
//        params.alpha = 0.92f;
        window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
        window.setAttributes(params);// 设置生效

        LayoutInflater fac = LayoutInflater.from(context);
        View more_pop_menu = fac.inflate(R.layout.dialog_gundong_time, null);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setContentView(more_pop_menu);
        params.height = android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
        params.width = getWindowManager().getDefaultDisplay().getWidth();
        dialog.show();
        dialog.setCallBack(new BaseDialog.CallBack() {
            @Override
            public void onTouchOutside() {
                sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.CLOCKORDER, "0");
                dialog.dismiss();
            }
        });
        new TimeOnClick(dialog, more_pop_menu, time_tv);
    }

    class TimeOnClick {

        private View view;
        private Dialog dialog;
        // private PickerView hour_pv;
        // private PickerView minute_pv;
        CycleWheelView hour_cy;
        CycleWheelView min_cy;
        String hour;
        String minute;
        private String timeSet;
        private TextView time_tv;

        Map<String, String> mMap;
        ToggleButton toggleButton;

        @SuppressLint("NewApi")
        public TimeOnClick(Dialog dialog, View view, TextView time_tv) {
            this.dialog = dialog;
            this.view = view;
            this.time_tv = time_tv;
            timeSet = time_tv.getText().toString();
            initview();
            initdata();
        }

        private void initview() {
            hour_cy = (CycleWheelView) view.findViewById(R.id.hour_cy);
            min_cy = (CycleWheelView) view.findViewById(R.id.min_cy);

//            view.findViewById(R.id.bp).setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    dialog.dismiss();
//                    initDiaLog(time_tv);
//                }
//            });

            toggleButton = (ToggleButton) view.findViewById(R.id.toggle);
            if (timeSet.equals("全天")) {
                toggleButton.setChecked(true);
                timeSet = "23:59";
            } else {
                toggleButton.setChecked(false);
            }
            toggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView,
                                             boolean isChecked) {
                    if (isChecked) {
                        time_tv.setText("全天");
                    } else {
                        time_tv.setText(timeSet);
                    }
                }
            });
        }

        private void initdata() {
            int curHours = Integer.parseInt(timeSet.split(":")[0]);
            int curMinutes = Integer.parseInt(timeSet.split(":")[1]);
            hour = curHours + "";
            minute = curMinutes + "";
            int currentHoursIndex = 0;
            int currentMinutesIndex = 0;
            List<String> hours = new ArrayList<String>();
            List<String> minutes = new ArrayList<String>();
            for (int i = 0; i < 24; i++) {
                hours.add(i < 10 ? "0" + i : "" + i);

            }
            for (int i = 0; i < 60; i++) {
                minutes.add(i < 10 ? "0" + i : "" + i);
            }
            for (int i = 0; i < hours.size(); i++) {
                if (curHours == Integer.parseInt(hours.get(i))) {
                    currentHoursIndex = i;
                }
            }
            for (int i = 0; i < minutes.size(); i++) {
                if (curMinutes == Integer.parseInt(minutes.get(i))) {
                    currentMinutesIndex = i;
                }
            }
            hour_cy.setLabels(hours);
            try {
                hour_cy.setWheelSize(5);
            } catch (CycleWheelView.CycleWheelViewException e) {
                e.printStackTrace();
            }
            hour_cy.setCycleEnable(true);
            hour_cy.setSelection(currentHoursIndex);
            hour_cy.setAlphaGradual(0.6f);
            hour_cy.setDivider(context.getResources().getColor(R.color.gongkai_txt), 1);
            hour_cy.setSolid(Color.WHITE, Color.WHITE);
            hour_cy.setLabelColor(context.getResources().getColor(R.color.gongkai_txt));
            hour_cy.setLabelSelectColor(Color.BLACK);
            hour_cy.setOnWheelItemSelectedListener(new CycleWheelView.WheelItemSelectedListener() {
                @Override
                public void onItemSelected(int position, String label) {
                    hour = Integer.parseInt(label) < 10 ? "0"
                            + Integer.parseInt(label) : label;
                    minute = Integer.parseInt(minute) < 10 ? "0"
                            + Integer.parseInt(minute) : minute;

                    if (!timeSet.equals(hour + ":" + minute)) {
                        toggleButton.setChecked(false);
                    }
                    timeSet = hour + ":" + minute;
                    if (toggleButton.isChecked() == false) {
                        time_tv.setText(hour + ":" + minute);
                    }
                }
            });

            min_cy.setLabels(minutes);
            try {
                min_cy.setWheelSize(5);
            } catch (CycleWheelView.CycleWheelViewException e) {
                e.printStackTrace();
            }
            min_cy.setCycleEnable(true);
            min_cy.setSelection(currentMinutesIndex);
            min_cy.setAlphaGradual(0.6f);
            min_cy.setDivider(context.getResources().getColor(R.color.gongkai_txt), 1);
            min_cy.setSolid(Color.WHITE, Color.WHITE);
            min_cy.setLabelColor(context.getResources().getColor(R.color.gongkai_txt));
            min_cy.setLabelSelectColor(Color.BLACK);
            min_cy.setOnWheelItemSelectedListener(new CycleWheelView.WheelItemSelectedListener() {
                @Override
                public void onItemSelected(int position, String label) {
                    hour = Integer.parseInt(hour) < 10 ? "0"
                            + Integer.parseInt(hour) : hour;
                    minute = Integer.parseInt(label) < 10 ? "0"
                            + Integer.parseInt(label) : label;
                    if (!timeSet.equals(hour + ":" + minute)) {
                        toggleButton.setChecked(false);
                    }
                    timeSet = hour + ":" + minute;
                    if (toggleButton.isChecked() == false) {
                        time_tv.setText(hour + ":" + minute);
                    }
                }
            });
        }
    }
}
